﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using WarningForeverClone.src.ships;
using Microsoft.Xna.Framework.Graphics;

namespace WarningForeverClone.src.weapons
{
    public abstract class Weapon
    {
        Vector2 position;
        protected Vector2 velocity;
        bool alive;
        private double rotation; //in radians

        public Weapon(Vector2 initalVelocity)
        {
            velocity = initalVelocity;
            rotation = 0;
        }

        public void ApplyForce(Vector2 force)
        {
            velocity += force;
        }
        public virtual void Update()
        {
            position +=  Velocity;
        }
        public void Collide(ShipPart part)
        {
            //blow up and stuff
            alive = false;
        }
        public virtual void Reset()
        {
            position = Vector2.Zero;
        }
        public void Draw(SpriteBatch sb)
        {
            if (alive)
            {
                sb.Draw(Texture, position, null, Color.White, (float)rotation, new Vector2(Texture.Width/2, Texture.Height/2), 1,SpriteEffects.None, 0);
            }
        }
        public bool IsOnScreen()
        {
            if (position.Y +50 < 0 || position.X +50< 0 || position.X > MainGame.ScreenSize.X || position.Y > MainGame.ScreenSize.Y )
                return false;
            return true;
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        public virtual Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }

        public bool Alive
        {
            get { return alive; }
            set { alive = value; }
        }

        /// <summary>
        /// The width and height of this weapon
        /// </summary>
        public Vector2 Dimensions
        {
            get
            {
                return new Vector2(Texture.Width, Texture.Height);
            }
        }
        /// <summary>
        /// The acceleration of this weapon as it moves
        /// </summary>
        public abstract Vector2 Acceleration
        {
            get;
        }
        /// <summary>
        /// How much damage this weapon does to an ship
        /// </summary>
        public abstract float Damage
        {
            get;
        }
        /// <summary>
        /// The texture for this weapon
        /// </summary>
        public abstract Texture2D Texture
        {
            get;
        }
        /// <summary>
        /// The data of this texture. Used for per-pixel intersection
        /// </summary>
        public abstract Color[] TextureData
        { get; }
        public double Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }
    }
}
